﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.MonoRail.Framework;
using Rodunu.Movies.Contracts;
using Rodunu.Movies.Interfaces.Subscriptions;
using Rodunu.Movies.Interfaces.User;
using Rodunu.Movies.Logic.Subscriptions;
using Rodunu.Movies.Logic.User;

namespace Rodunu.Movies.Web.ViewComponents
{
    public class MovieListMenuComponent : ViewComponent
    {
        public override void Render()
        {
            long userId = Convert.ToInt64(Context.ComponentParameters["UserId"]);

            try
            {
                IUser userLogic = new UserLogic();
                UserInfo user = userLogic.Find(userId);
                ISubscriptions subscriptionsLogic = new SubscriptionsLogic();
                if (subscriptionsLogic.IsActiveService(user, ExternalServices.Netflix) && !String.IsNullOrEmpty(user.NetflixId))
                {
                    if (user.Id == userId)
                        PropertyBag["ShowNetflix"] = true;
                    else if (user.AllowToViewQueue)
                        PropertyBag["ShowNetflix"] = true;
                    
                }
            }
            catch (Exception)
            {
            }

            PropertyBag["IsActive"] = Convert.ToString(Context.ComponentParameters["IsActive"]);
            PropertyBag["IsDetail"] = Convert.ToBoolean(Context.ComponentParameters["IsDetail"]);
            if (Context.ComponentParameters["IsLink"] != null)
                PropertyBag["IsLink"] = Convert.ToBoolean(Context.ComponentParameters["IsLink"]);
            else
                PropertyBag["IsLink"] = false;
            base.Render();
        }
    }
}
